package com.dunka.demo.util;

import java.util.HashMap;
import java.util.Map;

public class RestResponseUtil {
    public static RestResponse success() {
        RestResponse response = new RestResponse();
        response.setCode(RestCode.OK.code);
        response.setMsg(RestCode.OK.msg);
        response.setData(null);
        return response;
    }
    
    public static RestResponse success(Object data) {
        RestResponse response = new RestResponse();
        response.setCode(RestCode.OK.code);
        response.setMsg(RestCode.OK.msg);
        response.setData(data);
        return response;
    }
    
    public static RestResponse requestRefused(String msg) {
        RestResponse response = new RestResponse();
        response.setCode(RestCode.REQUEST_REFUSED.code);
        response.setMsg(RestCode.REQUEST_REFUSED.msg + ": " + msg);
        response.setData(null);
        return response;
    }
    
    public static RestResponse success(String key, String value) {
        RestResponse response = new RestResponse();
        response.setCode(RestCode.OK.code);
        response.setMsg(RestCode.OK.msg);
        Map<String, String> data = new HashMap<>();
        data.put(key, value);
        response.setData(data);
        return response;
    }
    
    public static RestResponse requestUnsupported() {
        RestResponse response = new RestResponse();
        response.setCode(RestCode.REQUEST_UNSUPPORTED.code);
        response.setMsg(RestCode.REQUEST_UNSUPPORTED.msg);
        response.setData(null);
        return response;
    }
    
    public static RestResponse notFound() {
        RestResponse response = new RestResponse();
        response.setCode(RestCode.NOT_FOUND.code);
        response.setMsg(RestCode.NOT_FOUND.msg);
        response.setData(null);
        return response;
    }
    
    public static RestResponse formatError(String param) {
        RestResponse response = new RestResponse();
        response.setCode(RestCode.FORMAT_ERROR.code);
        response.setMsg(RestCode.FORMAT_ERROR.msg + ": " + param);
        response.setData(null);
        return response;
    }
    
    public static RestResponse invalid(String msg) {
        RestResponse response = new RestResponse();
        response.setCode(RestCode.INVALID.code);
        response.setMsg(RestCode.INVALID.msg + ": " + msg);
        response.setData(null);
        return response;
    }
    
    public static RestResponse CaptchaError() {
        RestResponse response = new RestResponse();
        response.setCode(RestCode.CAPTCHA_ERROR.code);
        response.setMsg(RestCode.CAPTCHA_ERROR.msg);
        response.setData(null);
        return response;
    }
    public static RestResponse failure(String msg){
        RestResponse response = new RestResponse();
        response.setCode(RestCode.FAILURE.code);
        response.setMsg(RestCode.FAILURE.msg + ": " + msg);
        response.setData(null);
        return response;
    }
}
